#include <SDL/SDL.h>
#include "creature.h"

BMCreature::BMCreature(){
	x = 0.0f;
	y = 0.0f;
	z = 0.0f;
	rotx = 0.0f; 
	roty = 0.0f;
	rotz = 0.0f;
	health  = 0;
	for(int i = 0; i < QUAD_PRISM; i++)
		for(int d = 0; d < XYZ; d ++)
			coor[i][d] = 0.0f;
	direction = 0;
	jump_dis = 0.5;
}

void BMCreature::setHealth(int h){
	health = h;
}

int BMCreature::getHealth(){
	return health;
}

float BMCreature::getX(){
	return x;
}

float BMCreature::getY(){
	return y;
}

float BMCreature::getZ(){
	return z;
}

float BMCreature::getRotX(){
	return rotx;
}

float BMCreature::getRotY(){
	return roty;
}

float BMCreature::getRotZ(){
	return rotz;
}

void BMCreature::setCoor(int lessthaneight, float cx, float cy, float cz){
	coor[lessthaneight][0] = cx;
	coor[lessthaneight][1] = cy;
	coor[lessthaneight][2] = cz;
}

void BMCreature::getCoor(int lessthaneight, float *cx, float *cy, float *cz){
	*cx = coor[lessthaneight][0];
	*cy = coor[lessthaneight][1];
	*cz = coor[lessthaneight][2];
}

void BMCreature::move(float mx, float my, float mz){
	x = mx;
	y = my;
	z = mz;
}

void BMCreature::rotate(float rx, float ry, float rz){
	rotx = rx;
	roty = ry;
	rotz = rz;
}

int BMCreature::levelCollision(BMLevel *level){
	for(int i=0; i < QUAD_PRISM; i++){
		if(level->collision(coor[i][0] + x,coor[i][1] + y,coor[i][2] + z))
			return 1;
	}
	return 0;
}

void BMCreature::resetDirection(){
	if(((direction & DIR_RIGHT)||(direction & DIR_LEFT))&&( (direction & DIR_UP)||( direction & DIR_DOWN))){
		direction = 0;
		cout << endl << " %1 " << endl;
	}
	if(((direction & DIR_RIGHT)||(direction & DIR_LEFT))&&( (direction & DIR_FRONT)||( direction & DIR_BACK))){
		cout << endl << " %2 " << (direction & DIR_RIGHT) << (direction & DIR_FRONT || direction & DIR_BACK) << endl;
		direction = 0;
	}
	if(((direction & DIR_FRONT)||(direction & DIR_BACK))&&( (direction & DIR_UP)||( direction & DIR_DOWN))){
		direction = 0;
		cout << endl << " %3 " << endl;
	}
}

